﻿namespace EveKillboard.Core.Base
{
    using Interfaces;
    using System.ComponentModel.DataAnnotations;
    using System;

    [Table("Entities")]
    public abstract class EntityBase : IEntity, IEquatable<EntityBase>
    {
        [Key]
        [Column("ID")]
        public virtual int Id { get; set; }
        [Column("Name")]
        [StringLength(200)]
        public virtual string Name { get; set; }
        [Column("EveID")]
        public virtual int? EveId { get; set; }
        [Column("LastKnownParentID")]
        public virtual int? LastKnowParentId { get; set; }
        [Column("IsNpc")]
        public virtual bool? IsNpc { get; set; }
        [Column("IsStructure")]
        public virtual bool? IsStructure { get; set; }
        [Column("Updated")]
        public virtual DateTime? Updated { get; set; }
        
        public override string ToString()
        {
            return Name;
        }

        public bool Equals(EntityBase other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.Id == Id;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (EntityBase)) return false;
            return Equals((EntityBase) obj);
        }

        public override int GetHashCode()
        {
            return Id;
        }
    }
}